package com.thinkfit.jy.fragment;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.common.lib.activity.BaseActivity;
import com.common.lib.fragment.BaseFragment;
import com.common.lib.manager.DataManager;
import com.common.lib.mvp.contract.EmptyContract;
import com.common.lib.mvp.presenter.EmptyPresenter;
import com.common.lib.utils.BaseUtils;
import com.thinkfit.jy.R;
import com.thinkfit.jy.activity.MainActivity;
import com.thinkfit.jy.utils.BackButtonViewUtils;
import com.thinkfit.jy.utils.CountDownViewUtils;
import com.thinkfit.jy.utils.DeviceTypeUtils;
import com.thinkfit.jy.utils.DialogCloseApkViewUtils;
import com.thinkfit.jy.utils.DialogViewUtils;
import com.thinkfit.jy.utils.LoadViewUtils;
import com.thinkfit.jy.utils.SafetyLockViewUtils;
import com.thinkfit.jy.utils.SetTargetViewUtils;
import com.thinkfit.jy.utils.ShowBackButtonViewUtils;
import com.thinkfit.jy.utils.ShowSpeedViewUtils;
import com.thinkfit.jy.utils.SportsStatusBarViewUtils;

/**
 * 语言选择界面
 */
public class SwitchLanguageFragment extends BaseFragment<EmptyContract.Presenter> implements EmptyContract.View {
    @NonNull
    @Override
    protected EmptyContract.Presenter onCreatePresenter() {
        return new EmptyPresenter(this);
    }

    @Override
    protected int getLayoutId() {
//        return DataManager.Companion.getInstance().getMainStyle() == 3 ? R.layout.fragment_switch_language_xm : R.layout.fragment_switch_language;
        return R.layout.fragment_language;
    }

    @Override
    protected void initView(@NonNull View view, @Nullable Bundle savedInstanceState) {
        showLanguage();
        setViewsOnClickListener(R.id.llChinese,R.id.llOldChinese, R.id.llEnglish);
    }


    private void showLanguage() {
        int language = DataManager.Companion.getInstance().getLanguage();
        if (language == 0) {
            setViewVisible(R.id.ivChinese);
            setViewGone(R.id.ivEnglish);
            setViewGone(R.id.ivOldChinese);
        } else if (language == 1) {
            setViewGone(R.id.ivChinese);
            setViewGone(R.id.ivOldChinese);
            setViewVisible(R.id.ivEnglish);
        }else {
            setViewGone(R.id.ivChinese);
            setViewGone(R.id.ivEnglish);
            setViewVisible(R.id.ivOldChinese);
        }
    }



    @Override
    public void onStop() {
        super.onStop();
        System.out.println("ddddddddddddddddddddddd   SwitchLanguageFragment ");
        DeviceTypeUtils.showBackButton(getContext().getApplicationContext());
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.llChinese:
                DataManager.Companion.getInstance().saveLanguage(0);
                BaseUtils.StaticParams.changeAppLanguage(getActivity(), 0);
                SportsStatusBarViewUtils.getInstance().invaliView();
                ShowSpeedViewUtils.getInstance().invaliView();
                DialogViewUtils.getInstance().invaliView();
                BackButtonViewUtils.getInstance().invaliView();
                SetTargetViewUtils.getInstance().invaliView();
                DialogCloseApkViewUtils.getInstance().invaliView();
                LoadViewUtils.getInstance().invaliView();
                ShowBackButtonViewUtils.getInstance().cleanView();
                CountDownViewUtils.getInstance().invaliView();
                SafetyLockViewUtils.getInstance().invaliView();
                ((BaseActivity) getActivity()).finishAllActivity();
                openActivity(MainActivity.class);
                break;
            case R.id.llEnglish:
                DataManager.Companion.getInstance().saveLanguage(1);
                BaseUtils.StaticParams.changeAppLanguage(getActivity(), 1);
                SportsStatusBarViewUtils.getInstance().invaliView();
                ShowSpeedViewUtils.getInstance().invaliView();
                DialogViewUtils.getInstance().invaliView();
                BackButtonViewUtils.getInstance().invaliView();
                SetTargetViewUtils.getInstance().invaliView();
                DialogCloseApkViewUtils.getInstance().invaliView();
                LoadViewUtils.getInstance().invaliView();
                ShowBackButtonViewUtils.getInstance().cleanView();
                CountDownViewUtils.getInstance().invaliView();
                SafetyLockViewUtils.getInstance().invaliView();
                ((BaseActivity) getActivity()).finishAllActivity();
                openActivity(MainActivity.class);
                break;
            case R.id.llOldChinese:
                DataManager.Companion.getInstance().saveLanguage(2);
                BaseUtils.StaticParams.changeAppLanguage(getActivity(), 2);
                SportsStatusBarViewUtils.getInstance().invaliView();
                ShowSpeedViewUtils.getInstance().invaliView();
                DialogViewUtils.getInstance().invaliView();
                BackButtonViewUtils.getInstance().invaliView();
                SetTargetViewUtils.getInstance().invaliView();
                DialogCloseApkViewUtils.getInstance().invaliView();
                LoadViewUtils.getInstance().invaliView();
                ShowBackButtonViewUtils.getInstance().cleanView();
                CountDownViewUtils.getInstance().invaliView();
                SafetyLockViewUtils.getInstance().invaliView();
                ((BaseActivity) getActivity()).finishAllActivity();
                openActivity(MainActivity.class);
                break;
        }
    }
}
